package com.example.demo.controller;

import com.example.demo.domain.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.example.demo.service.userService;

import java.util.List;


@RestController
@RequestMapping("/api/users") //路径要符合 /api/**
public class userController {

    @Autowired
    private userService userService;

    @GetMapping
    public List<User> getAllUsers() {
        return userService.getAllUsers();
    }

    @PostMapping
    public void addUser(
            @RequestBody User user) {
        userService.addUser(user);
    }

    @PutMapping
    public void updateUser(
            @RequestBody User user) {
        userService.updateUser(user);
    }

    @DeleteMapping("/{id}")
    public void deleteUser(
            @PathVariable Long id) {
        userService.deleteUser(id);
    }

}
